home *** CD-ROM | disk | FTP | other *** search
/ Aminet 44 / Aminet 44 (2001)(GTI - Schatztruhe)[!][Aug 2001].iso / Aminet / dev / gui / gtlayout.lha / Source / LTP_DrawGroup.c < prev    next >
C/C++ Source or Header  |  1999-10-11  |  11KB  |  470 lines

  1. /*
  2. **    GadTools layout toolkit
  3. **
  4. **    Copyright © 1993-1999 by Olaf `Olsen' Barthel
  5. **        Freely distributable.
  6. **
  7. **    :ts=4
  8. */
  9.  
  10. #ifndef _GTLAYOUT_GLOBAL_H
  11. #include "gtlayout_global.h"
  12. #endif
  13.  
  14. /****************************************************************************/
  15.  
  16. #include <hardware/blit.h>
  17.  
  18. /****************************************************************************/
  19.  
  20. #include "Assert.h"
  21.  
  22. /****************************************************************************/
  23.  
  24. #define MINTERM_B_OR_C      (ABC | ABNC | NABC | NABNC | ANBC | NANBC)
  25. #define MINTERM_B_EQUALS_C  (ABC | ANBNC | NABC | NANBNC)
  26.  
  27. /****************************************************************************/
  28.  
  29. VOID
  30. LTP_DrawObjectLabel(LayoutHandle *Handle,ObjectNode *Node)
  31. {
  32.     if(Node->Label)
  33.     {
  34.         LONG Left,Top,GlyphHeight = Handle->GlyphHeight;
  35.  
  36.         switch(Node->LabelPlace)
  37.         {
  38.             case PLACE_LEFT:
  39.  
  40.                 Left    = Node->Left;
  41.                 Top        = Node->Top + (Node->Height - GlyphHeight) / 2;
  42.  
  43.                 break;
  44.  
  45.             case PLACE_RIGHT:
  46.  
  47.                 Left    = Node->Left + Node->Width + INTERWIDTH + INTERWIDTH + Node->LabelWidth;
  48.                 Top        = Node->Top + (Node->Height - GlyphHeight) / 2;
  49.  
  50.                 break;
  51.  
  52.             case PLACE_ABOVE:
  53.  
  54.                 Left    = Node->Left + (Node->Width - Node->LabelWidth) / 2 + INTERWIDTH + Node->LabelWidth;
  55.                 Top        = Node->Top - (GlyphHeight + INTERHEIGHT);
  56.  
  57.                 break;
  58.  
  59.             case PLACE_BELOW:
  60.  
  61.                 Left    = Node->Left + (Node->Width - Node->LabelWidth) / 2 + INTERWIDTH + Node->LabelWidth;
  62.                 Top        = Node->Top + Node->Height + INTERHEIGHT;
  63.  
  64.                 break;
  65.  
  66.             default:
  67.  
  68.                 return;    /* Only if none of the placement types match; should never happen! */
  69.         }
  70.  
  71.         LTP_PrintLabel(Handle,Node,Left,Top);
  72.     }
  73. }
  74.  
  75. /****************************************************************************/
  76.  
  77. #define ANY_OBJECT -32768
  78.  
  79. /****************************************************************************/
  80.  
  81. VOID
  82. LTP_DrawGroup(LayoutHandle *Handle,ObjectNode *Group)
  83. {
  84.     LTP_DrawGroupMember(Handle,Group,ANY_OBJECT);
  85. }
  86.  
  87. BOOL
  88. LTP_DrawGroupMember(LayoutHandle *Handle,ObjectNode *Group,LONG id)
  89. {
  90.     BOOL found = FALSE;
  91.     ObjectNode *Node;
  92.     ULONG page;
  93.     LONG i;
  94.  
  95.     if(id == ANY_OBJECT || Group->ID == id)
  96.     {
  97.         if(Group->Label || Group->Special.Group.Frame || Group->Special.Group.FrameType == FRAMETYPE_Label)
  98.         {
  99.             LTP_DrawGroupLabel(Handle,Group);
  100.         }
  101.         else
  102.         {
  103.             if(Group->Special.Group.FrameType == FRAMETYPE_Tab)
  104.                 LTP_DrawGroupFrame(Handle,Group);
  105.         }
  106.     }
  107.  
  108.     SCANPAGE(Group,Node,page)
  109.     {
  110.         if(id != ANY_OBJECT && Node->ID != id)
  111.             continue;
  112.  
  113.         switch(Node->Type)
  114.         {
  115.             case BLANK_KIND:
  116.  
  117.                 found = TRUE;
  118.  
  119.                 break;
  120.  
  121.             #ifdef OLD_STYLE_DEFAULT_KEY
  122.             {
  123.                 case BUTTON_KIND:
  124.  
  125.                     if(Handle->ReturnKey == Node)
  126.                         LTP_DrawBevelBox(Handle,Node);
  127.  
  128.                     found = TRUE;
  129.  
  130.                     break;
  131.             }
  132.             #endif
  133.  
  134.             #ifdef DO_GAUGE_KIND
  135.             {
  136.                 case GAUGE_KIND:
  137.                 {
  138.                     LONG Percent = Node->Current;
  139.  
  140.                     Node->Current = 0;
  141.  
  142.                     LTP_DrawGauge(Handle,Node,Percent,TRUE);
  143.  
  144.                     found = TRUE;
  145.  
  146.                     break;
  147.                 }
  148.             }
  149.             #endif
  150.  
  151.             case PALETTE_KIND:
  152.  
  153.                 if(Node->Special.Palette.UsePicker)
  154.                     LTP_DrawPalette(Handle,Node);
  155.  
  156.                 found = TRUE;
  157.  
  158.                 break;
  159.  
  160.             case GROUP_KIND:
  161.  
  162.                 if(Node->Label)
  163.                     LTP_DrawGroupLabel(Handle,Node);
  164.  
  165.                 LTP_DrawGroupMember(Handle,Node,id);
  166.  
  167.                 found = TRUE;
  168.  
  169.                 break;
  170.  
  171.             case XBAR_KIND:
  172.             {
  173.                 LONG Top = Node->Top + ((Node->Height + 1) / 2) - 1;
  174.                 struct RastPort *RPort = &Handle->RPort;
  175.  
  176.                 if(Node->Special.Bar.FullSize)
  177.                 {
  178.                     LTP_SetAPen(RPort,Handle->ShadowPen);
  179.                     LTP_DrawLine(RPort,Handle->Window->BorderLeft,Top,Handle->Window->Width - (Handle->Window->BorderRight + 1),Top);
  180.  
  181.                     LTP_SetAPen(RPort,Handle->ShinePen);
  182.                     LTP_DrawLine(RPort,Handle->Window->BorderLeft,Top + 1,Handle->Window->Width - (Handle->Window->BorderRight + 1),Top + 1);
  183.                 }
  184.                 else
  185.                 {
  186.                     LONG Room,Left;
  187.  
  188.                     Left = Node->Special.Bar.Parent->Left;
  189.  
  190.                     if(Node->Special.Bar.Parent->Label)
  191.                         Room = 2 * Handle->GlyphWidth;
  192.                     else
  193.                         Room = 0;
  194.  
  195.                     LTP_SetAPen(RPort,Handle->ShadowPen);
  196.                     LTP_PolyDraw(RPort,3,
  197.                         Left + Room,Top + 1,
  198.                         Left + Room,Top,
  199.                         Left + Node->Special.Bar.Parent->Width - 1 - 1 - Room,Top);
  200.  
  201.                     LTP_SetAPen(RPort,Handle->ShinePen);
  202.                     LTP_PolyDraw(RPort,3,
  203.                         Left + Room + 1,Top + 1,
  204.                         Left + Node->Special.Bar.Parent->Width - 1 - Room,Top + 1,
  205.                         Left + Node->Special.Bar.Parent->Width - 1 - Room,Top);
  206.                 }
  207.  
  208.                 found = TRUE;
  209.  
  210.                 break;
  211.             }
  212.  
  213.             case YBAR_KIND:
  214.             {
  215.                 LONG Left = Node->Left + ((Node->Width + 1) / 2) - 1,Room;
  216.                 struct RastPort *RPort = &Handle->RPort;
  217.  
  218.                 if(Node->Special.Bar.Parent->Label)
  219.                     Room = Handle->GlyphHeight + Handle->InterHeight;
  220.                 else
  221.                     Room = 0;
  222.  
  223.                 LTP_SetAPen(RPort,Handle->ShadowPen);
  224.                 LTP_PolyDraw(RPort,3,
  225.                     Left + 1,    Node->Special.Bar.Parent->Top + Room,
  226.                     Left,        Node->Special.Bar.Parent->Top + Room,
  227.                     Left,        Node->Special.Bar.Parent->Top + Node->Special.Bar.Parent->Height - 1 - 1 - Room);
  228.  
  229.                 LTP_SetAPen(RPort,Handle->ShinePen);
  230.                 LTP_PolyDraw(RPort,3,
  231.                     Left + 1,    Node->Special.Bar.Parent->Top + Room + 1,
  232.                     Left + 1,    Node->Special.Bar.Parent->Top + Node->Special.Bar.Parent->Height - 1 - Room,
  233.                     Left,        Node->Special.Bar.Parent->Top + Node->Special.Bar.Parent->Height - 1 - Room);
  234.  
  235.                 if((Handle->AspectY + Handle->AspectX - 1) / Handle->AspectX >= 2)
  236.                 {
  237.                     LTP_SetAPen(RPort,Handle->ShadowPen);
  238.                     LTP_DrawLine(RPort,    Left - 1,    Node->Special.Bar.Parent->Top + Room,
  239.                                 Left - 1,    Node->Special.Bar.Parent->Top + Node->Special.Bar.Parent->Height - 1 - Room);
  240.  
  241.                     LTP_SetAPen(RPort,Handle->ShinePen);
  242.                     LTP_DrawLine(RPort,    Left + 2,    Node->Special.Bar.Parent->Top + Room,
  243.                                 Left + 2,    Node->Special.Bar.Parent->Top + Node->Special.Bar.Parent->Height - 1 - Room);
  244.                 }
  245.  
  246.                 found = TRUE;
  247.  
  248.                 break;
  249.             }
  250.  
  251.             case IMAGE_KIND:
  252.  
  253.                 if(Node->Special.Image.Image != NULL)
  254.                     DrawImage(&Handle->RPort,Node->Special.Image.Image,Node->Left,Node->Top);
  255.                 else
  256.                 {
  257.                     UWORD    left    = Node->Special.Image.BitMapLeft,
  258.                             top        = Node->Special.Image.BitMapTop,
  259.                             width    = Node->Special.Image.BitMapWidth,
  260.                             height    = Node->Special.Image.BitMapHeight;
  261.  
  262.                     if(Node->Special.Image.BitMapMask == NULL)
  263.                     {
  264.                         BltBitMapRastPort(Node->Special.Image.BitMap,left,top,
  265.                                           &Handle->RPort,Node->Left,Node->Top,
  266.                                           width,height,0xC0);
  267.                     }
  268.                     else
  269.                     {
  270.                         struct BitMap *source = Node->Special.Image.BitMap;
  271.                         struct RastPort *destination = &Handle->RPort;
  272.                         BOOL isInterleaved = FALSE;
  273.  
  274.                         if(V39)
  275.                         {
  276.                             if(GetBitMapAttr(Node->Special.Image.BitMap,BMA_FLAGS) & BMF_INTERLEAVED)
  277.                                 isInterleaved = TRUE;
  278.                         }
  279.  
  280.                         if(isInterleaved)
  281.                         {
  282.                             struct BitMap mask;
  283.                             LONG i;
  284.  
  285.                             InitBitMap(&mask,8,GetBitMapAttr(Node->Special.Image.BitMap,BMA_WIDTH),GetBitMapAttr(Node->Special.Image.BitMap,BMA_HEIGHT));
  286.                             for(i = 0 ; i < 8 ; i++)
  287.                                 mask.Planes[i] = Node->Special.Image.BitMapMask;
  288.  
  289.                             BltBitMapRastPort(source,left,top,destination,Node->Left,Node->Top,width,height,MINTERM_B_EQUALS_C);
  290.                             BltBitMapRastPort(&mask,left,top,destination,Node->Left,Node->Top,width,height,MINTERM_B_OR_C);
  291.                             BltBitMapRastPort(source,left,top,destination,Node->Left,Node->Top,width,height,MINTERM_B_EQUALS_C);
  292.                         }
  293.                         else
  294.                         {
  295.                             BltMaskBitMapRastPort(source,left,top,destination,Node->Left,Node->Top,width,height,(ABC | ABNC | ANBC),Node->Special.Image.BitMapMask);
  296.                         }
  297.                     }
  298.                 }
  299.  
  300.                 found = TRUE;
  301.  
  302.                 LTP_DrawObjectLabel(Handle,Node);
  303.                 break;
  304.  
  305.             case FRAME_KIND:
  306.  
  307.                 if(Node->Special.Frame.DrawBox)
  308.                     LTP_DrawBevelBox(Handle,Node);
  309.  
  310.                 if(Node->Special.Frame.RefreshHook)
  311.                 {
  312.                     RefreshMsg Message;
  313.  
  314.                     Message.ID        = Node->ID;
  315.                     Message.Left    = Node->Left;
  316.                     Message.Top        = Node->Top;
  317.                     Message.Width    = Node->Width;
  318.                     Message.Height    = Node->Height;
  319.  
  320.                     if(Node->Special.Frame.DrawBox)
  321.                     {
  322.                         Message.Left    += 4;
  323.                         Message.Top        += 2;
  324.                         Message.Width    -= 8;
  325.                         Message.Height    -= 4;
  326.                     }
  327.  
  328.                     CallHookPkt(Node->Special.Frame.RefreshHook,Handle,&Message);
  329.                 }
  330.  
  331.                 // FALL THROUGH TO...
  332.  
  333.             case POPUP_KIND:
  334.  
  335.                 // FALL THROUGH TO...
  336.  
  337.             case TEXTEDIT_KIND:
  338.  
  339.                 // FALL THROUGH TO...
  340.  
  341.             case TAPEDECK_KIND:
  342.  
  343.                 found = TRUE;
  344.  
  345.                 LTP_DrawObjectLabel(Handle,Node);
  346.                 break;
  347.  
  348.             case MX_KIND:
  349.  
  350.                 if(Node->Label && !V39)
  351.                     LTP_PrintLabel(Handle,Node,Node->Left,Node->Top + (Node->Height - Handle->GlyphHeight) / 2 + 1);
  352.  
  353.                 found = TRUE;
  354.  
  355.                 break;
  356.  
  357.             #ifdef DO_LEVEL_KIND
  358.             {
  359.                 case LEVEL_KIND:
  360.  
  361.                     LTP_LevelGadgetDrawLabel(Handle,Node,TRUE);
  362.  
  363.                     found = TRUE;
  364.  
  365.                     break;
  366.             }
  367.             #endif    /* DO_LEVEL_KIND */
  368.  
  369.             case LISTVIEW_KIND:
  370.             {
  371.                 struct RastPort *RPort = &Handle->RPort;
  372.  
  373.                 if(Node->Special.List.ExtraLabels)
  374.                 {
  375.                     LTP_SetPens(RPort,Handle->TextPen,0,JAM1);
  376.  
  377.                     for(i = 0 ; Node->Special.List.ExtraLabels[i] ; i++)
  378.                     {
  379.                         LONG Len = strlen(Node->Special.List.ExtraLabels[i]);
  380.  
  381.                         LTP_PrintText(RPort,Node->Special.List.ExtraLabels[i],Len,Node->Left - (TextLength(RPort,Node->Special.List.ExtraLabels[i],Len) + INTERWIDTH),Node->Top + 2 + i * Handle->GlyphHeight);
  382.                     }
  383.                 }
  384.  
  385.                 if(Node->Label)
  386.                 {
  387.                     if(Node->LabelPlace == PLACE_ABOVE && Node->Special.List.FlushLabelLeft)
  388.                     {
  389.                         struct TextFont *Font = NULL,*OldFont = NULL;
  390.  
  391.                         if(Node->Special.List.TextAttr)
  392.                         {
  393.                             if(Font = LTP_OpenFont(Node->Special.List.TextAttr))
  394.                             {
  395.                                 OldFont = RPort->Font;
  396.  
  397.                                 SetFont(RPort,Font);
  398.                             }
  399.                             else
  400.                                 break;
  401.                         }
  402.  
  403.                         LTP_PrintLabel(Handle,Node,Node->Left + 2 + INTERWIDTH + Node->LabelWidth,Node->Top - (Handle->GlyphHeight + INTERHEIGHT));
  404.  
  405.                         if(Font)
  406.                         {
  407.                             SetFont(RPort,OldFont);
  408.  
  409.                             CloseFont(Font);
  410.                         }
  411.                     }
  412.                     else
  413.                     {
  414.                         if(Node->Special.List.TextAttr)
  415.                             LTP_DrawObjectLabel(Handle,Node);
  416.                     }
  417.                 }
  418.  
  419.                 found = TRUE;
  420.  
  421.                 break;
  422.             }
  423.  
  424.             case BOX_KIND:
  425.             {
  426.                 struct RastPort *RPort = &Handle->RPort;
  427.  
  428.                 Node->Special.Box.Parent = Group;
  429.  
  430.                 if(Node->Special.Box.DrawBox)
  431.                     LTP_DrawBevelBox(Handle,Node);
  432.  
  433.                 for(i = 0 ; i < Node->Lines ; i++)
  434.                 {
  435.                     if(Node->Special.Box.Labels && Node->Special.Box.Labels[i])
  436.                     {
  437.                         LONG Len = strlen(Node->Special.Box.Labels[i]);
  438.  
  439.                         LTP_SetPens(RPort,Handle->TextPen,0,JAM1);
  440.                         LTP_PrintText(RPort,Node->Special.Box.Labels[i],Len,Node->Left - (TextLength(RPort,Node->Special.Box.Labels[i],Len) + INTERWIDTH),Node->Top + 2 + i * (Handle->GlyphHeight + Node->Special.Box.Spacing));
  441.                     }
  442.  
  443.                     LTP_PrintBoxLine(Handle,Node,i);
  444.                 }
  445.  
  446.                 found = TRUE;
  447.  
  448.                 break;
  449.             }
  450.  
  451.             #ifdef DO_BOOPSI_KIND
  452.             {
  453.                 case BOOPSI_KIND:
  454.  
  455.                     LTP_DrawObjectLabel(Handle,Node);
  456.  
  457.                     if(id == Node->ID)
  458.                         RefreshGList(Node->Host,Handle->Window,NULL,1);
  459.  
  460.                     found = TRUE;
  461.  
  462.                     break;
  463.             }
  464.             #endif /* DO_BOOPSI_KIND */
  465.         }
  466.     }
  467.  
  468.     return(found);
  469. }
  470.